<?php
/*
Developer: Alex Arey
Updated: 3/30/2012
Module Description: Handles general query operations for administrative users.
Separated from other controllers to allow customized data without adding further complexity to existing controllers and views.
*/


class AdminqueryController extends Zend_Controller_Action
{

    public function init(){
		//get user session
       	$auth = Zend_Auth::getInstance();
		
		//check if user is logged in, otherwise redirect to home page
		if($auth->hasIdentity()){
			$userID = $auth->getIdentity()->getUID();
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
		$this->checkAdmin();
		
		
    }
	
	private function checkAdmin(){
		$auth = Zend_Auth::getInstance();
		if($auth->hasIdentity()){
			$userRank = $auth->getIdentity()->getUserRank();
			if($userRank<2){
						$this->_helper->redirector('index','index');
						return;
			}
		}else{
			$this->_helper->redirector('index','index');
			return;
		}
	
	}
	
	
	
    public function indexAction(){
		$this->_helper->redirector('partner','adminquery');
    }
    
    public function partnerAction(){
    	$partnerModel = new Application_Model_DbTable_Organizations();
    	$noteModel = new Application_Model_DbTable_Notes();
    	$partners = $partnerModel->getAllOrganizations();
    	$viewPartners = array();
    	foreach($partners as $p){
    		$viewPartners[] = array(
    			'ID'=>$p['ID'],
    			'NAME'=>$p['NAME'],
    			'PHONE'=>$p['PHONE'],
    			'EMAIL'=>$p['EMAIL'],
    			'NOTE'=>$noteModel->getPartnerNote($p['ID'])
    		);
    	}
    	$this->view->partners = $viewPartners;
    }
	
	    public function coursesAction(){
    	$partnerModel = new Application_Model_DbTable_Organizations();
    	$noteModel = new Application_Model_DbTable_Notes();
    	$partners = $partnerModel->getAllOrganizations();
    	$viewPartners = array();
    	foreach($partners as $p){
    		$viewPartners[] = array(
    			'ID'=>$p['ID'],
    			'NAME'=>$p['NAME'],
    			'PHONE'=>$p['PHONE'],
    			'EMAIL'=>$p['EMAIL'],
    			'NOTE'=>$noteModel->getPartnerNote($p['ID'])
    		);
    	}
    	$this->view->partners = $viewPartners;
    }

}
?>
